using UnityEngine;
using ZCTouchDrawBoard;
using ZCUIManager;

namespace ZCUtil.DoubleBuffer
{
    /// <summary>
    /// DoublePaper: 双纹理, 较为高效
    /// </summary>
    public class DoublePaper
    {
        private const int PAPER_A = 0;
        private const int PAPER_B = 1;

        private BasePaperView[] mDoublePaper;

        public BasePaperView PaperA
        {
            get
            {
                return mDoublePaper[PAPER_A];
            }
            set
            {
                mDoublePaper[PAPER_A] = value;
            }
        }

        public BasePaperView PaperB
        {
            get
            {
                return mDoublePaper[PAPER_B];
            }
            set
            {
                mDoublePaper[PAPER_B] = value;
            }
        }

        public int Width
        {
            get
            {
                return mDoublePaper[PAPER_A].Width;
            }
        }

        public int Height
        {
            get
            {
                return mDoublePaper[PAPER_A].Height;
            }
        }

        public DoublePaper(int width, int height, int depth = 16)
        {
            mDoublePaper = new AlphaPaperView[2];
            for (int i = 0; i < 2; i++)
            {
                mDoublePaper[i] = UIManager.Instance.GetUIView<AlphaPaperView>(eUIType.AlphaPaperView);
                mDoublePaper[i].Initialize(width, height, depth);
                mDoublePaper[i].rectTransform.position = (i + 1) * Vector3.one * 10.0f;
                // mDoublePaper[i].Hide();
            }
        }

        public void UseA()
        {
            PaperA.Use();
        }

        public void ClearA()
        {
            PaperA.Clear();
        }

        public void UseB()
        {
            PaperB.Use();
        }

        public void ClearB()
        {
            PaperB.Clear();
        }

        public void SwapAB()
        {
            BasePaperView temp = PaperA;
            PaperA = PaperB;
            PaperB = temp;
        }

        public void Release()
        {
            for (int i = 0; i < 2; i++)
            {
                mDoublePaper[i].Release();
            }
        }
    }
}
